/*
 * Dalek.h
 *
 *  Created on: Jan 30, 2013
 *      Author: baneling
 */

#ifndef DALEK_H_
#define DALEK_H_

#include "PngPlus.h"
#include <libplayerc++/playerc++.h>

using namespace PlayerCc;
using namespace std;

//struct obstacles_s
//{
//	bool sensorError;
//	bool _90;
//	bool _180;
//	bool _270;
//	bool _0;
//}typedef obstacles_t;

class Dalek {
public:
	Dalek(string name,string address, uint32_t positionProxyIndex,uint32_t sonarProxyIndex,uint32_t bloblfinderProxyIndex, uint32_t simulationProxyIndex,bool initFiles,bool verbose);
	~Dalek();
	//	obstacles_t initObstaclesPosition(obstacles_t obt);
	void run(); //N.B. while(true) method

private://internal methods
	void stopFormation();
	int intmin(int a, int b);
	double getQval(qItem_t q);
	qItem_t getMaxOfGroup(qItem_t max,qGroup_t group);
	double getFamilyMean(qFam_t family);
	void getBestAction(int x, int y);
	void avoidObstaclesWithTarget();
	void getVision();
	bool turnToYawGlobalSafe(double yaw,double errormargin=2);
	void turn();
	state_t getCurrState(state_t currState);
	qItem_t getCurrItemData(qItem_t item);
	double distance(double ax, double ay, double bx, double by);
	int getDalek90Yaw();
	void navigate ();
	void initBias(bool flag);
	double calculateQvalue(double learning,qFam_t hereFamily);
	bool haveToNavigate(qItem_t currItem);

private: /* attributes*/
	PlayerClient *robotClient;
	Position2dProxy *p2dProxy;
	SonarProxy *sonarProxy;
	BlobfinderProxy *blobProxy;
	SimulationProxy *simProxy;
//	obstacles_t obstaclesPosition;
	coordinates_t cabCoord;
	int formationYaw;
	int bestYaw;
	int randYaw;
	int temperature;
	double forwardspeed;
	double turnspeed;
	double reinforcement;
	bool obstacle;
	bool isfirstMove;
	FileTree *ft;
	PngPlus *pp;
	bool seeingPink;
	double pinkWidth;
	bool seeingOrange;
	coordinates_t myCoord;
	string dalekName;
	qItem_t oldQitem;
};

#endif /* DALEK_H_ */
